package com.sunnada.exam.controller;

import com.sunnada.exam.service.ResultsService;
import com.sunnada.exam.vo.ResultsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/results")
public class ResultsController {

    @Autowired
    ResultsService resultsService;

    @GetMapping
    public String resultsListPage(Map<String, Object> model){
        List<ResultsVo> list = resultsService.listPage();
        model.put("results",resultsService.listPage());
        return "results";
    }

    @GetMapping("{id}")
    public String resultsOnePage(@PathVariable String id,Map<String, Object> model){
        model.put("one",resultsService.one(id));
        return "one";
    }

    @GetMapping("/delete/{id}")
    public String delete(@PathVariable String id,Map<String, Object> model){
        resultsService.delete(id);
        model.put("results",resultsService.listPage());
        return "results";
    }

}
